//
//  RouteListCell.m
//  Cycling
//
//  Created by 迟国强 on 2023/4/5.
//

#import "RouteListCell.h"
#import "RouteDetailModel.h"

@implementation RouteListCell

- (void)awakeFromNib {
    [super awakeFromNib];
    self.selectionStyle = UITableViewCellSelectionStyleNone;

    self.bgView.layer.cornerRadius = 16;
    self.bgView.layer.masksToBounds = YES;
    // Initialization code
}

- (IBAction)clickedGoodBtn:(UIButton *)sender {
    if (self.goodBlock) {
        self.goodBlock(self.model);
    }
}

- (IBAction)clickedCollectionBtn:(UIButton *)sender {
    if (self.collectionBlock) {
        self.collectionBlock(self.model);
    }
}

- (void)setModel:(RouteDetailModel *)model {
    _model = model;
    [self.routeImageView sd_setImageWithURL:[NSURL URLWithString:model.lineimg]];
    if(model.imgs.count){
        [self.routeImageView sd_setImageWithURL:[NSURL URLWithString:model.imgs.firstObject]];
    }else {
        if(model.lineimg.length){
            [self.routeImageView sd_setImageWithURL:[NSURL URLWithString:model.lineimg]];
        }
    }

    self.routeImageView.contentMode = UIViewContentModeScaleAspectFill;
    self.routeImageView.clipsToBounds = YES;
    self.routeNameL.text = model.name;
    self.distanceL.text = [NSString stringWithFormat:@"%.2fkm",model.actualdistance.floatValue/1000.0];
    self.timeL.text = model.timelength;
    self.velocityL.text = [NSString stringWithFormat:@"%@m",model.climb];
    self.kcalL.text = model.calories;
    self.addressL.text = model.endpost;
    [self.collectionBtn setTitle:model.collectionnum forState:UIControlStateNormal];
    [self.goodBtn setTitle:model.praisenum forState:UIControlStateNormal];
    if (model.iscollection) {
        [self.collectionBtn setImage:[UIImage imageNamed:@"收藏_select"] forState:UIControlStateNormal];
    } else {
        [self.collectionBtn setImage:[UIImage imageNamed:@"收藏"] forState:UIControlStateNormal];
    }
    if (model.ispraise) {
        [self.goodBtn setImage:[UIImage imageNamed:@"点赞_select"] forState:UIControlStateNormal];
    } else {
        [self.goodBtn setImage:[UIImage imageNamed:@"点赞"] forState:UIControlStateNormal];
    }
    
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
    [super setSelected:selected animated:animated];
    
}

@end
